<?php
	//include_once('Models/LopHocPhan.php');
	if (isset($_POST['btndownload'])){
		//$malophp = $_GET['malophp'];
        header("Content-Type: application/vnd.ms-word;");
        header("Content-Disposition: attachment; filename=".$_GET['maso'].".doc");
        echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
	}
	include_once('Configs/database.php');
	include_once('Models/NhatKi.php');
	include_once('Models/LopHocPhan.php');
	include_once('Models/NhomThucHanh.php');
	$nhatki = new NhatKi();;
	$lophp = new LopHocPhan();
	
	$dbhk2 = new database();
	$dbhk3 = new database();
	$dbhk1 = new database();
	$dbhk2_2 = new database();
	$dbhk3_2 = new database();
	$dbhk1_2 = new database();
	//$namhoc = $_GET['namhoc'];
	//$hocki = $_GET['hocki'];
	//$maso = $_GET['maso'];
	//$namhoc = $_POST['namhoc'];
	//$hocki = $_POST['hocki'];
	//$maso = $_POST['maso'];
	//hoc kì 2
	$namhk23 = ($nam-1)."-".$nam;
	$namhk1 = $nam."-".($nam+1);
	$queryhk2 = "select distinct tenhp,kihieu,sotc,a.malophp,siso,a.mahp,manhom,sotietlithuyet,sotietthuchanh,hocki ";
	$queryhk2 .= "from LopHocPhan a, HocPhan b ";
	$queryhk2 .= "where maso='".$maso."' and hocki=2 and namhoc='".$namhk23."' ";
	$queryhk2 .= "and a.mahp = b.mahp order by a.mahp ";
	$dbhk2->setQuery($queryhk2);
	$resulthk2 = $dbhk2->fetchAll();
	//hoc ki he
	$queryhk3 = "select distinct tenhp,kihieu,sotc,a.malophp,siso,a.mahp,manhom,sotietlithuyet,sotietthuchanh,hocki ";
	$queryhk3 .= "from LopHocPhan a, HocPhan b ";
	$queryhk3 .= "where maso='".$maso."' and hocki=3 and namhoc='".$namhk23."' ";
	$queryhk3 .= "and a.mahp = b.mahp order by a.mahp ";
	$dbhk3->setQuery($queryhk3);
	$resulthk3 = $dbhk3->fetchAll();
	//hoc ki 1
	$queryhk1 = "select distinct tenhp,kihieu,sotc,a.malophp,siso,a.mahp,manhom,sotietlithuyet,sotietthuchanh,hocki ";
	$queryhk1 .= "from LopHocPhan a, HocPhan b ";
	$queryhk1 .= "where maso='".$maso."' and hocki=1 and namhoc='".$namhk1."' ";
	$queryhk1 .= "and a.mahp = b.mahp order by a.mahp ";
	$dbhk1->setQuery($queryhk1);
	$resulthk1 = $dbhk1->fetchAll();
	//thuc hanh
	//hoc ki 2
	$queryhk2_2 = "select distinct tenhp,c.kihieu,sotc,a.malophp,manhomth,c.siso,a.mahp,manhom,sotietlithuyet,sotietthuchanh,hocki ";
	$queryhk2_2 .= "from LopHocPhan a, HocPhan b,NhomThucHanh c ";
	$queryhk2_2 .= "where c.maso='".$maso."' and hocki=2 and namhoc='".$namhk23."' ";
	$queryhk2_2 .= "and a.mahp = b.mahp and a.malophp=c.malophp order by a.mahp ";
	$dbhk2_2->setQuery($queryhk2_2);
	$resulthk2_2 = $dbhk2_2->fetchAll();
	//hoc ki 3
	
	$queryhk3_2 = "select distinct tenhp,c.kihieu,sotc,a.malophp,manhomth,c.siso,a.mahp,manhom,sotietlithuyet,sotietthuchanh,hocki ";
	$queryhk3_2 .= "from LopHocPhan a, HocPhan b,NhomThucHanh c ";
	$queryhk3_2 .= "where c.maso='".$maso."' and hocki=3 and namhoc='".$namhk23."' ";
	$queryhk3_2 .= "and a.mahp = b.mahp and a.malophp=c.malophp order by a.mahp ";
	$dbhk3_2->setQuery($queryhk3_2);
	$resulthk3_2 = $dbhk3_2->fetchAll();
	//hoc ki 1
	$queryhk1_2 = "select distinct tenhp,c.kihieu,sotc,a.malophp,manhomth,c.siso,a.mahp,manhom,sotietlithuyet,sotietthuchanh,hocki ";
	$queryhk1_2 .= "from LopHocPhan a, HocPhan b,NhomThucHanh c ";
	$queryhk1_2 .= "where c.maso='".$maso."' and hocki=1 and namhoc='".$namhk1."' ";
	$queryhk1_2 .= "and a.mahp = b.mahp and a.malophp=c.malophp order by a.mahp ";
	$dbhk1_2->setQuery($queryhk1_2);
	$resulthk1_2 = $dbhk1_2->fetchAll();
	
	
	$tonglthk1 = 0;
	$tonglthk2 = 0;
	$tonglthk3 = 0;
	/*$result2 = $db->fetchAll();
	$result3 = $db->fetchAll();
	$result4 = $db->fetchAll();
	$result5 = $db->fetchAll();
	
	$query2 = "select distinct tenhp,c.kihieu,sotc,a.malophp,manhomth,c.siso,a.mahp,manhom,sotietlithuyet,sotietthuchanh ";
	$query2 .= "from LopHocPhan a, HocPhan b,NhomThucHanh c ";
	$query2 .= "where c.maso='".$maso."' and hocki=".$hocki." and namhoc='".$namhoc."' ";
	$query2 .= "and a.mahp = b.mahp and a.malophp=c.malophp order by a.mahp ";
	$db2->setQuery($query2);
	$result2 = $db2->fetchAll();*/
	$nhomth = new NhomThucHanh();
	
	
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="Libraries/css/style.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>

<body>
<form name="khoiluonggd" method="POST">
<table align="center" class="font" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="main_1"><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align="center" class="main_1">Khối Lượng Giảng Dạy- Học kì:
      <?php echo $hocki?>-Năm học:<?php echo $namhoc?></td>
    <td class="main_1"><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
	<table width="100%" align="center" class="border_1" cellpadding="0" cellspacing="0">
		 <tr>
			<td colspan="14" align="center" class="main_3" >Cán Bộ: <?php echo $hoten?> - MSCB: <?php echo $maso?></td>
		</tr>
	  <tr>
		<td width="4%" rowspan="2" align="center" valign="middle" class="main_3"><strong>STT</strong></td>
		<td width="24%" rowspan="2" align="center" valign="middle" class="main_3" ><strong>Nội dungMã HP </strong></td>
		<td width="6%" rowspan="2" align="center" valign="middle" class="main_3"><strong>Ký hiệu </strong></td>
	
		<td width="5%" rowspan="2" align="center" valign="middle" class="main_3"><strong>DVHT</strong></td>
		<td width="5%" rowspan="2" align="center" valign="middle" class="main_3"><strong>Lớp</strong></td>
		<td width="5%" rowspan="2" align="center" valign="middle" class="main_3"><strong>Số SV </strong></td>
		<td width="6%" rowspan="2" align="center" valign="middle" class="main_3"><strong>Số nhóm </strong></td>
		<td width="5%" rowspan="2" align="center" valign="middle" class="main_3"><strong>Giờ thực tế </strong></td>
		<td width="5%" rowspan="2" align="center" valign="middle" class="main_3"><strong>Hệ số quy dổi </strong></td>
	
		<td colspan="3" align="center" valign="middle" class="main_3"><strong>Giờ chuẩn theo học kỳ</strong></td>
		<td width="10%" rowspan="2" align="center" valign="middle" class="main_3"><strong>Tổng số giờ dạy CQ </strong></td>
	  </tr>
	  <tr>
		<td width="6%" align="center" valign="middle" class="main_3"><strong>HKII</strong></td>
		<td width="4%" align="center" valign="middle" class="main_3"><strong>HK hè </strong></td>
		<td width="4%" align="center" valign="middle" class="main_3"><strong>HKI</strong></td>
	  </tr>
	  <tr>
		<td align="center" valign="middle" class="main_3">1</td>
		<td colspan="12" align="left" valign="middle" class='level_1_2'><strong>Giảng dạy lý thuyết CĐ,ĐH CQ </strong></td>
	  </tr>
	  <?php
		$i = 0;		
	  while ($rows = mysql_fetch_array($resulthk2))
	  {	
		$hocki = $rows['hocki'];
		$lophp->setMaLopHP($rows['malophp']);
		$tonglthk1 = $tonglthk1 + $lophp->tongSoTietDaDay();
		$tonglthk2 = $tonglthk2 + $lophp->tongSoTietDaDay();
		$tonglthk3 = $tonglthk3 + $lophp->tongSoTietDaDay();
		//$nhatki->setMaLopHP($rows['malophp']);
		if ($rows['manhom']==1 || $rows['manhom']==3 )
		{
			$i++;
			$c = 2- $i%2;
	  ?>
		  <tr>
			<td align="right" valign="middle" class="main_3">1.<?php echo $i?>&nbsp;</td>
			<td align="left" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;&nbsp;<?php echo $rows['tenhp']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['kihieu']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['sotc']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['malophp']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['siso']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
		
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==2) echo round($lophp->tongSoTietDaDay(),0);?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==3) echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==1) echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
		  </tr>
		<?php
			}
		}
		?>
	  <?php
		$i = 0;		
	  while ($rows = mysql_fetch_array($resulthk3))
	  {	
		$hocki = $rows['hocki'];
		$lophp->setMaLopHP($rows['malophp']);
		//$tonglthk1 = $tonglthk1 + $lophp->tongSoTietDaDay();
		//$tonglthk2 = $tonglthk2 + $lophp->tongSoTietDaDay();
		$tonglthk3 = $tonglthk3 + $lophp->tongSoTietDaDay();
		//$nhatki->setMaLopHP($rows['malophp']);
		if ($rows['manhom']==1 || $rows['manhom']==3 )
		{
			$i++;
			$c = 2- $i%2;
	  ?>
		  <tr>
			<td align="right" valign="middle" class="main_3">1.<?php echo $i?>&nbsp;</td>
			<td align="left" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;&nbsp;<?php echo $rows['tenhp']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['kihieu']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['sotc']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['malophp']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['siso']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
		
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==2) echo round($lophp->tongSoTietDaDay(),0);?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==3) echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==1) echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
		  </tr>
		<?php
			}
		}
		?>
	  <?php
		$i = 0;		
	  while ($rows = mysql_fetch_array($resulthk1))
	  {	
		$hocki = $rows['hocki'];
		$lophp->setMaLopHP($rows['malophp']);
		$tonglthk1 = $tonglthk1 + $lophp->tongSoTietDaDay();
		$tonglthk2 = $tonglthk2 + $lophp->tongSoTietDaDay();
		$tonglthk3 = $tonglthk3 + $lophp->tongSoTietDaDay();
		//$nhatki->setMaLopHP($rows['malophp']);
		if ($rows['manhom']==1 || $rows['manhom']==3 )
		{
			$i++;
			$c = 2- $i%2;
	  ?>
		  <tr>
			<td align="right" valign="middle" class="main_3">1.<?php echo $i?>&nbsp;</td>
			<td align="left" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;&nbsp;<?php echo $rows['tenhp']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['kihieu']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['sotc']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['malophp']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['siso']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
		
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==2) echo round($lophp->tongSoTietDaDay(),0);?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==3) echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==1) echo $lophp->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
		  </tr>
		<?php
			}
		}
		?>
	  <tr>
		<td align="center" valign="middle" class="main_3">&nbsp;</td>
		<td colspan="8" align="left" valign="middle"><strong>Cộng</strong></td>
	
		<td align="center" valign="middle"><b>
		  <?php if ($hocki==2) echo $tonglthk2;?>
		</b></td>
		<td align="center" valign="middle"><b>
		  <?php if ($hocki==3) echo $tonglthk3;?>
		</b></td>
		<td align="center" valign="middle"><b>
		  <?php if ($hocki==1) echo $tonglthk1;?>
		</b></td>
		<td align="center" valign="middle">&nbsp;</td>
	  </tr>
	  <tr>
		<td align="center" valign="middle" class="main_3">2</td>
		<td colspan="12" align="left" valign="middle" class='level_1_2'><strong>Dạy thực hành, thí nghiệm </strong></td>
	  </tr>
	   <?php
			$i = 0;
			$tongthhk1 = 0;
			$tongthhk2 = 0;
			$tongthhk3 = 0;
		  	
		  while ($rows = mysql_fetch_array($resulthk1_2))
		  {	
			
			$nhomth->setMaNhomTH($rows['manhomth']);
			$tongthhk1 = $tongthhk1 + ($nhomth->getHeSo()*$nhomth->tongSoTietDaDay());
			$tongthhk2 = $tongthhk2 + ($nhomth->getHeSo()*$nhomth->tongSoTietDaDay());
			$tongthhk3 = $tongthhk3 + ($nhomth->getHeSo()*$nhomth->tongSoTietDaDay());
			if ($rows['manhom']==2 || $rows['manhom']==3 )
			{
				$i++;
				$c = 2- $i%2;
		  ?>
	  <tr>
			<td align="right" valign="middle" class="main_3">2.<?php echo $i?>&nbsp;</td>
			<td align="left" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;&nbsp;<?php echo $rows['tenhp']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['kihieu']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['sotc']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['manhomth']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $rows['siso']?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
		
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php echo $nhomth->getHeSo()*$nhomth->tongSoTietDaDay();?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==2) echo round($nhomth->getHeSo()*$nhomth->tongSoTietDaDay(),0);?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==3) echo round($nhomth->getHeSo()*$nhomth->tongSoTietDaDay(),0);?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'><?php if ($hocki==1) echo round($nhomth->getHeSo()*$nhomth->tongSoTietDaDay(),0);?></td>
			<td align="center" valign="middle" class='level_1_<?php echo $c?>'>&nbsp;</td>
	  </tr>
		<?php
			}
		}
		?>
	  <tr>
		<td align="center" valign="middle" class="main_3">&nbsp;</td>
		<td colspan="8" align="left" valign="middle" class='level_1_1'><strong>Cộng</strong></td>
		<td align="left" valign="middle" class='level_1_1'><b><?php if ($hocki==2) echo round($tongthhk2);?></b></td>
		<td align="left" valign="middle" class='level_1_1'><b><?php if ($hocki==3) echo round($tongthhk3);?></b></td>
		<td align="center" valign="middle" class='level_1_1'><b><?php if ($hocki==1) echo round($tongthhk1);?></b></td>
		<td align="center" valign="middle" class='level_1_1'>&nbsp;</td>
	  </tr>
	  
	  
	  
	  <tr>
		<td colspan="13" align="center" valign="middle"><input type="button" name="btndownload" value="Download" onclick="printTL('<?php echo $namhoc?>','<?php echo $hocki?>','<?php echo $maso?>')"/></td>
		</tr>
	</table>
</table>
</form>
</body>
</html>
